﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;

namespace LotteryAdmin
{
    public class ModelCopy
    {
       public static T CopyValueForModel<T>(T org)where T : new() 
        {
            T dest = new T();
            foreach (PropertyInfo po in org.GetType().GetProperties())
            {
                foreach (PropertyInfo pd in dest.GetType().GetProperties())
                {
                    if (pd.Name == po.Name)
                    {
                        pd.SetValue(dest, po.GetValue(org, null), null);
                        break;
                    }
                }
            }
            return dest;
        }

       public static T CopyValueForModel<T>(T org,T dest) where T : new()
       {
           if (dest == null)
               dest = new T();
           foreach (PropertyInfo po in org.GetType().GetProperties())
           {
               foreach (PropertyInfo pd in dest.GetType().GetProperties())
               {
                   if (pd.Name == po.Name)
                   {
                       pd.SetValue(dest, po.GetValue(org, null), null);
                       break;
                   }
               }
           }
           return dest;
       }

       public static bool ComPareModelValue<T>(T org, T dest) where T : new()
       {
           bool result = true;
           foreach (PropertyInfo po in org.GetType().GetProperties())
           {
               foreach (PropertyInfo pd in dest.GetType().GetProperties())
               {
                   if (pd.Name == po.Name)
                   {
                       if (po.GetValue(org, null) != pd.GetValue(dest, null))
                       {
                           result = false;
                       }
                       break;
                   }
               }
               if(!result)
                   break;
           }
           return result;
       }
    }
}
